package cn.leonis.leetcode;

/**
 * @Author Tobi
 * @Date 2021-07-23 下午5:01
 * 删除排序链表中的重复元素2
 */
public class RemoveDuplicatesFromSortedList2Solution {

    public static void main(String[] args) {

    }

    /**
     * 删除重复元素
     * @param head
     * @return
     */
    public ListNode deleteDuplicates(ListNode head) {
        if (head == null) {
            return head;
        }

        ListNode dummy = new ListNode(0, head);

        ListNode current = dummy;

        while (current.next != null && current.next.next != null) {
            if (current.next.val == current.next.next.val) {
                int val = current.next.val;
                while (current.next != null && current.next.val == val) {
                    current.next = current.next.next;
                }
            } else {
                current = current.next;
            }
        }

        return dummy.next;
    }
}
